package com.qf.flash.ui.home.adapter;

import android.view.View;
import android.widget.ImageView;

import com.qf.flash.R;
import com.qf.flash.model.MyCollectShopBean;
import com.qf.flash.ui.home.BusinessDetailActivity;
import com.qf.flash.utils.ImageLoader;
import com.qf.flash.widget.RatingBarView;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;

/**
 * 收藏的商家item
 */
public class CollectShopItem extends BaseRViewItem<Object> {

    private CheckedListener checkedListener;

    public void setCheckedListener(CheckedListener checkedListener) {
        this.checkedListener = checkedListener;
    }

    @Override
    public boolean isItemView(Object entity, int position) {
        return entity instanceof MyCollectShopBean;
    }

    @Override
    public int getItemLayout() {
        return R.layout.item_shop;
    }

    @Override
    public void convert(RViewHolder holder, Object entity, int position, int itemSize) {
        MyCollectShopBean bean = (MyCollectShopBean) entity;
        ImageView imageView=holder.getView(R.id.iv_head);
        RatingBarView rbvStar = holder.getView(R.id.rbv_star);
        rbvStar.setStar((int) Math.round(bean.getResponseScole()), false);
        ImageLoader.load(holder.getmConvertView().getContext(),bean.getLogo(),imageView);
        holder.setText(R.id.tv_title,bean.getShopName());
//        holder.setText(R.id.tv_address,bean.getShopName());
        holder.setVisible(R.id.tv_address,false);
        holder.setText(R.id.tv_type_name,bean.getRunTypeName());
        holder.setText(R.id.tv_score,bean.getResponseScole()+"分");
        holder.setText(R.id.tv_distance,bean.getRangeNumStr());

        holder.getView(R.id.rl_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BusinessDetailActivity.start(holder.getmConvertView().getContext(), "", bean.getShopId(),"", false);
            }
        });
        //----------------------------------  选择器
        ImageView ivShow = holder.getView(R.id.iv_main);
        if (bean.isShow) {
            ivShow.setVisibility(View.VISIBLE);
        } else {
            ivShow.setVisibility(View.GONE);
        }

        ivShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkedListener.setChecked(position, bean.isChecked);
            }
        });


        if (bean.isChecked) {
            ivShow.setImageResource(R.mipmap.icon_check);
        } else {
            ivShow.setImageResource(R.mipmap.icon_uncheck);
        }



    }

    public interface CheckedListener {
        void setChecked(int position, boolean ischecked);
    }
}
